package cn.wolfcode.web.interceptor;

import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginInterceptor implements HandlerInterceptor {



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        //先从session中 获取当前 登录用户
        Object employee = request.getSession().getAttribute(UserContext.USER_IN_SESSION);

        //判断是否为空
        if(employee==null){
            response.sendRedirect("/login.html");
            return false;
        }
        //为 空 > 重定向 到 登录界面 不放行

        //不为空 ->直接放行

        return true;
    }
}
